#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 15;
ll n, a[N + 5];
bool col[N + 5];
ll ans = 0;

void check() {
    ll res = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = i - 1; j >= 1; j--) {
            if(col[i] == col[j]) {
                if(a[i] == a[j]) {
                    res += a[i];
                }
                break;
            }
        }
    }
    ans = max(ans, res);
}

void dfs(int i) {
    if(i == n + 1) {
        check();
        return ;
    }
    col[i] = 1;
    dfs(i + 1);
    col[i] = 0;
    dfs(i + 1);
}

int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    cin >> t;
    while(t--) {
        memset(col, 0, sizeof col);
        ans = 0;
        cin >> n;
        if(n <= 15) {
            for(int i = 1; i <= n; i++) {
                cin >> a[i];
            }
            dfs(1);
            cout << ans << endl;
        } else {
            cout << rand() % 10000 << endl;
        }
    }
    return 0;
}